package thread;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Created on 2020/6/1.
 */
public class ContainerNotSafeDemo {

    public static void main(String[] args) {

//        List<String> strList = new ArrayList<>();
//        List<String> strList = new Vector<>();
//        List<String> strList = Collections.synchronizedList(new ArrayList<>());
        List<String> strList = new CopyOnWriteArrayList<>();

        for (int i = 0; i < 30; i++) {
            new Thread(()->{
                strList.add(UUID.randomUUID().toString().substring(8));
                System.out.println(strList);
            }, String.valueOf(i)).start();
        }

        /*
        1 故障现象
        java.util.ConcurrentModificationException
        2 导致原因
        3 解决方案  1 Vector
                    2 Collections
                    3 CopyOnWriteArrayList
        4 优化建议(同样错误不犯)
        */

    }
}
